import django.db.models
from django.db import models
# user 模型
# Create your models here.
from django.utils import timezone
import application.address as address
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import AbstractUser  # 引入 然后继承 添加自己的项 （重写） 然后更改表名 出现新的表数据


class User(models.Model):

    del_info = (
        (0, '正常'),
        (1, '删除')
    )
    name = models.CharField(max_length=20, unique=True, null=False, verbose_name='昵称')
    mobile = models.CharField(max_length=11, unique=True, null=False, verbose_name='电话、账号')
    passwd_dj = models.CharField(max_length=32, null=False, verbose_name='密码')
    pay_passwd = models.CharField(max_length=6, default=None, verbose_name='支付密码')
    money = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='钱')
    integral = models.IntegerField(default=0, verbose_name='积分')
    create_time = models.DateTimeField(default=timezone.now, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='最后更新时间')
    login_time = models.DateTimeField(auto_now=True, verbose_name='最后登录时间')
    del_type = models.SmallIntegerField(choices=del_info, default=0, verbose_name='是否移除')

    class Meta:
        db_table = 'users'
        verbose_name = "用户管理"
        verbose_name_plural = verbose_name

    def set_password(self, raw_password):
        self.password = make_password(raw_password)
        self._password = raw_password

